package com.sx.micowell.framework.adapter

import android.content.Context
import android.graphics.drawable.DrawableContainer
import android.graphics.drawable.StateListDrawable
import android.widget.SimpleAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.mvvm.base.data.MutableLiveListData
import com.example.mvvm.until.GlideApp
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter
import com.miloyu.modelnet.response.*
import com.sx.micowell.R
import com.sx.micowell.databinding.ItemRecommendCourseBinding
import com.sx.micowell.databinding.ItemTrainStepBinding
import com.sx.micowell.framework.tools.DiffUtils

/**
 * @Description 训练步骤
 * @Author 梁浩文
 * @Date 2021/8/28 18:21
 */
class TrainStepAdapter (
    selectData: MutableLiveListData<TrainSelectData>,
    context: Context) : SimpleDataBindingAdapter<TrainListBeanInfo, ItemTrainStepBinding>(
    context,
    R.layout.item_train_step,
    DiffUtils.getInstance().trainListBeanInfoItemCallback
)
{
    var  selectData: MutableLiveListData<TrainSelectData>? = null;
    init {
        this.selectData=selectData
    }
    override fun onBindItem(
        binding: ItemTrainStepBinding,
        item: TrainListBeanInfo,
        holder: RecyclerView.ViewHolder?
    ) {
        //mContext.getResId("drawable","")

        var resId = mContext.getResId("drawable","ic_off_${item.id}")
        var resSelId = mContext.getResId("drawable","ic_on_${item.id}")
        if(resSelId!=0&&resId!=0){
            var sel=StateListDrawable()
            sel.addState(intArrayOf(android.R.attr.state_selected),mContext.getResDrawable(resSelId))
            sel.addState(intArrayOf(android.R.attr.state_enabled),mContext.getResDrawable(resId))
            binding.itemImageStep.setImageDrawable(sel)
        }
        binding.data=item;
        binding.itemLayoutStep.isSelected=false
        binding.itemImageStep.isSelected=false
        selectData?.value?.let {
           var get = it.stream().filter { (id, _) -> id == item.id }.count()
            binding.itemLayoutStep.isSelected=get!=0L
            binding.itemImageStep.isSelected=get!=0L
        }

    }
}